import scipy.stats
import numpy as np
# 已知总体方差
N = 5000  # 总数
n = 400  # 样本数
n1 = 32  # 样本废品数
p = n1 / n  # 样本废品率
alpha = 1 - 0.9

z = scipy.stats.norm.isf(alpha / 2)
ME = z * np.sqrt(p * (1 - p) / n) * np.sqrt((N - n) / (N - 1)) #不放回二项分布方差
low = p - ME
up = p + ME
print("({0},{1})".format(round(low, 5), round(up, 5)))
